using project1113.Wrold;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Speech.Recognition;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Tdmq.V20200217.Models;
using TencentCloud.Yunjing.V20180228.Models;
using project1113.SpeechRecoginzer;
using System.Windows.Threading;
using System.Xml.Linq;
using project1113.FSM;

namespace project1113.states
{
    public class WaitCallState: FsmState
    {
        private bool _Timeout = false;
        private static SpeechRecognitionEngine recognizer;
        string? _name = "";
        private System.Windows.Threading.DispatcherTimer _timer;
        public WaitCallState(string name):base("wait calling")
        {
            _name = name;
        }
        
            
        
        public override void Init()
        {
            WorldModel.CurrentWorld.Face.Running = false;    
            _timer = new DispatcherTimer();
            _timer.Interval = new TimeSpan(0, 0, 15); // 设置定时器间隔为30秒
            _timer.Tick += TimerTickFunc;
            _timer.IsEnabled = true;
            _timer.Start();
            //WorldModel.CurrentWorld.Face.HaveFace = false;
            WorldModel.CurrentWorld.TTS.Speak(_name+",你好");
        }
        public override void DoSomething()
        {
            WorldModel.CurrentWorld.SpeechRecoginzer.Mode = SpeechRecognizeMode.mode_Local;
            DisplayHelper.LoadPage("Hello");
        }
        public override FsmState GetNextState()
        {
            if (WorldModel.CurrentWorld.Security.GetSafe())
            {
                if (WorldModel.CurrentWorld.SpeechRecoginzer.local_IsCalled())
                {
                    return new InteractionAstate();
                }
                else if(_Timeout)
                {
                    return new WaitState();
                }
                else if (WorldModel.CurrentWorld.SpeechRecoginzer.local_Turnoff())
                {
                    return new WaitState();
                }
                else 
                {
                    return this;
                }
            }
            else
            {
                return new EmergenceState(this);
            }
          
        }
        private void TimerTickFunc(object sender, EventArgs e)
        {
            _Timeout = true;
        }

    }
}
